package com.bkgy.modular.tpdodatatcm2280.controller;

import com.alibaba.fastjson.JSON;
import com.bkgy.modular.tpdodatatcm2280.entity.TPdoDataTcm2280;
import com.bkgy.modular.tpdodatatcm2280.entity.TPdoDataTcm2280ForQuery;
import com.bkgy.modular.tpdodatatcm2280.service.TPdoDataTcm2280Service;
import com.bkgy.sys.common.entity.IndocnoEntity;
import com.bkgy.sys.common.entity.InsertAndUpdateEntity;
import com.bkgy.sys.common.entity.JCommon;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.CodiUtil;
import io.github.yedaxia.apidocs.ApiDoc;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 本地酸轧2280PDO
 * @author 生成器生成
 * @date 2025-04-03 22:17:14
 */
@ApiDoc
@RestController
@RequestMapping("/tPdoDataTcm2280")
public class TPdoDataTcm2280Controller {

    @Resource
    private TPdoDataTcm2280Service tPdoDataTcm2280Service;

    /**
    * 添加记录
    * @param insertAndUpdateEntity 插入与更新专用实体类
    * @param loginToken            请求头（包含userId（用户id） & sname 用户姓名）
    */
    @CrossOrigin
    @PostMapping("/insert")
    @ResponseBody
    public ResultData<Object> insertDataTPdoDataTcm2280(@RequestBody InsertAndUpdateEntity<TPdoDataTcm2280> insertAndUpdateEntity
            , @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tPdoDataTcm2280Service.insertDataTPdoDataTcm2280(insertAndUpdateEntity.getEntity(), userId, CodiUtil.returnLm(sname));
    }

    /**
     * 根据主键删除对象
     * @param indocnoEntity 主键专用实体类
     * */
    @CrossOrigin
    @PostMapping("/deleteOne")
    @ResponseBody
    public ResultData<Object> deleteDataTPdoDataTcm2280One(@RequestBody IndocnoEntity indocnoEntity) {
        try {
            return tPdoDataTcm2280Service.deleteOne(indocnoEntity.getIndocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 根据主键字符串删除多个对象
     * @param indocnoEntity 主键专用实体类
     * */
    @CrossOrigin
    @PostMapping("/deleteMany")
    @ResponseBody
    public ResultData<Object> deleteDataTPdoDataTcm2280Many(@RequestBody IndocnoEntity indocnoEntity) {
        try {
            return tPdoDataTcm2280Service.deleteMany(indocnoEntity.getStr_indocno());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("访问接口错误，错误信息为" + e.getMessage(), null);
        }
    }

    /**
     * 修改记录
     * @param insertAndUpdateEntity 插入与更新专用实体类
     * @param loginToken 请求头（包含userId（用户id） & sname 用户姓名）
     */
    @CrossOrigin
    @PostMapping("/update")
    @ResponseBody
    public ResultData<Object> updateDataTPdoDataTcm2280(@RequestBody InsertAndUpdateEntity<TPdoDataTcm2280> insertAndUpdateEntity
            , @RequestHeader(value = "loginToken") String loginToken) {
        JCommon common = JSON.parseObject(loginToken, JCommon.class);
        String sname = common.getSname();
        Long userId = common.getUserId();
        return tPdoDataTcm2280Service.updateDataTPdoDataTcm2280(insertAndUpdateEntity.getEntity(), userId, CodiUtil.returnLm(sname));
    }

    /**
     * 分页查看记录
     * @param tPdoDataTcm2280ForQuery 查询专用实体类
     */
    @CrossOrigin
    @PostMapping("/findByPage")
    @ResponseBody
    public ResultData<List<TPdoDataTcm2280>> findDataTPdoDataTcm2280ByPage(@RequestBody TPdoDataTcm2280ForQuery tPdoDataTcm2280ForQuery) {
        return tPdoDataTcm2280Service.findDataTPdoDataTcm2280ByPage(tPdoDataTcm2280ForQuery);
    }

    /**
     * 根据主键查询单条记录
     * @param indocnoEntity 主键专用实体类
     */
    @CrossOrigin
    @PostMapping("/findByIndocno")
    @ResponseBody
    public ResultData<TPdoDataTcm2280> findDataTPdoDataTcm2280ByIndocno(@RequestBody IndocnoEntity indocnoEntity) {
        return tPdoDataTcm2280Service.findDataTPdoDataTcm2280ByIndocno(indocnoEntity.getIndocno());
    }
}